import type {
  CodeRes,
  CodeType,
  PatientInfoType,
  PatientItem,
  PatientList,
  UserType
} from '@/types/user'
import { request } from '@/utils/request'

/**
 * 登录--密码登录
 * @param data 登录的参数 { mobile, password }
 * @returns Promise对象
 */
export const loginByPasswordAPI = (data: object) =>
  request<UserType>('/login/password', 'POST', data)

/**
 * 获取手机验证码
 * @param mobile 手机号
 * @param type 区分验证码的类型
 * @returns Promise对象
 */
export const sendMSMCode = (mobile: string, type: CodeType) =>
  request<CodeRes>('/code', 'GET', { mobile, type })

/**
 * 登录--手机验证码登录
 * @param mobile 手机号
 * @param code 短信验证码
 * @returns Promise对象
 */
export const loginByCodeAPI = (mobile: string, code: string) =>
  request<UserType>('/login', 'POST', { mobile, code })

/**
 * 注册
 * @param mobile 手机号码
 * @param code 验证码
 * @param password 密码
 * @returns Promise对象
 */
export const registerAPI = (mobile: string, code: string, password: string) =>
  request('/register', 'POST', { mobile, code, password })

/**
 * 我的-获取个人用户信息
 * @returns Promise对象
 */
export const getUserInfoAPI = () =>
  request<PatientInfoType>('/patient/myUser', 'GET')

/**
 * 问诊-查询患者列表信息
 * @returns Promise对象
 */
export const getPatientListAPI = () => request<PatientList>('/patient/mylist')

/**
 * 问诊-添加患者信息
 * @param patient 患者信息对象
 * @returns Promise对象
 */
export const addPatientAPI = (patient: PatientItem) =>
  request('/patient/add', 'POST', patient)

/**
 * 问诊-编辑患者信息
 * @param data 患者信息对象
 * @returns Promise对象
 */
export const editPatientAPI = (data: PatientItem) =>
  request('/patient/update', 'PUT', data)

/**
 * 问诊-删除患者信息
 * @param id 患者id
 * @returns Promise对象
 */
export const deletePatientAPI = (id: string) =>
  request(`/patient/del/${id}`, 'DELETE')

/**
 * 消息通知-所有未读数量
 * @returns Promise对象
 */
export const unReadAPI = () => request<number>('/patient/message/unRead/all')

/**
 * 登录--三方登录--qq三方登录
 * @param openId
 * @returns Promise对象
 */
export const loginByQQAPI = (openId: string) =>
  request<UserType>('/login/thirdparty', 'POST', { openId, source: 'qq' })

/**
 * 登录--绑定用户新-三方登录绑定手机号
 * @param data 请求参数
 * @returns
 */
export const bindMobileAPI = (data: {
  mobile: string
  code: string
  openId: string
}) => request<UserType>('/login/binding', 'POST', data)
